package com.dut.bbs.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dut.bbs.R;

public class Top10Adapter extends BaseAdapter {

	private List<Map<String, String>> ItemList;
	private LayoutInflater mInflater;

	public Top10Adapter(Context context, List<Map<String, String>> ItemList) {
		this.ItemList = ItemList;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return ItemList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return ItemList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.toptenlistitem, null);
			holder.tv_title = (TextView) convertView.findViewById(R.id.title);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		Map<String, String> dataMap = ItemList.get(position);
		holder.tv_title.setText(dataMap.get("title"));
		holder.url = dataMap.get("url");
		return convertView;
	}

	public class ViewHolder {
		public TextView tv_title;
		public String url;
	}
}
